import {TaskController} from "../controller/TaskController";
import {AchievementController} from "../controller/AchievementController";
import {UnitController} from "../controller/UnitController";
import {Util} from "../utils/Util";
import {LogType} from "../type/Type";
import {TriggerFactory} from "../frame/TriggerFactory";
import {PlayerModel} from "../frame/apiModel/adapterModel/model4/PlayerModel";
import {Logger} from "../frame/apiModel/config/Logger";

export function playerExitTrigger() {
    const onExit = function (this: void, player: PlayerModel) {
        const playerName = player.name;
        Logger.toastProduct(`玩家 ${playerName} 退出了游戏，清除他的所有单位！`)
        UnitController.getInstance().clearUnitByPlayer(player);
        AchievementController.getInstance().clearAchievementByPlayer(player);
        TaskController.getInstance().clearTaskByPlayer(player);
    }
    TriggerFactory.getInstance().registerPlayerLeave(onExit)
}